/**
 * Image control class.
 * Note: don't confuse with native Image class.
 * They are almost identical except that object of this class
 * is a block element, but native image is inline.
 *
 * @author Andrey Anisimov <hercules@inbox.ru>
 */

import core.ui.Window;

class Image extends Window {
	
	/**
	 * Creates new image.
	 * 
	 * @param parent (Window) [optional] parent window
	 * @param x, y (int) [optional] coordinates
	 * @param width, height (int) [optional] image size.
	 */		
	this.Image = function(parent, x, y, width, height) {
		super(parent, x, y, width, height);
		this.setStyle('display', 'block');
	}
	
	/**
	 * Sets URL for this image.
	 *
	 * @param src (string) image URL.
	 */
	this.setSource = function(src) {
		this.getElement().src = this.source = src;
	}
	
	/**
	 * Gets URL for this image.
	 *
	 * @return string
	 */
	this.getSource = function() {
		return this.source;
	}
	
	/**
	 * Gets whether this image is loaded.
	 *
	 * @return bool
	 */
	this.isLoaded = function() {
		return this.getElement().complete;
	}
	
	/**
	 * @protected
	 * Creates root element for Image.
	 *
	 * @return HTMLElement
	 */
	this.createElement = function() {
		var img = document.createElement('img');
		// FIX: there is a bug when a user tries to move an image box which is not selected.
		// IE shows "denied" cursor and the image box is not moved anywhere.
		img.ondragstart = new Function('return false');
		return img;
	}
}